﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using System.Text.RegularExpressions;

namespace IndyMosaic.Models
{
    public abstract class Validatable
    {
        protected bool IsValid
        {
            get { return GetRuleViolations().Count() == 0; }
        }
        abstract public IEnumerable<RuleViolation> GetRuleViolations();
        //public void OnValidate(ChangeAction action)
        //{
        //    if (!IsValid)
        //    {
        //        throw new ApplicationException("Rule violations prevent saving");
        //    }
        //}

        public static bool ValidEmailAddress(string emailAddress)
        {

            if (string.IsNullOrEmpty(emailAddress))
            {
                return false;
            }
            else
            {
                Regex reg = new Regex(@"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", RegexOptions.IgnoreCase);
                return reg.IsMatch(emailAddress);
            }
        }
    }
}
